Skip to content

feat: add PSRAM-DMA flag + runtime API for ESP32-S2/S3; remove 16MHz heuristic #774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

RubenKelevra
Copy link
Contributor

@RubenKelevra RubenKelevra commented Jul 17, 2025

Description

Add a Kconfig switch (CONFIG_CAMERA_PSRAM_DMA) to enable camera to PSRAM
DMA copy on ESP32-S2 and ESP32-S3 targets, in favor of removing the
undocumented "set XCLK=16MHz to enable PSRAM DMA" heuristic.

cam_hal.c:

  • Select psram_mode = true when CONFIG_CAMERA_PSRAM_DMA && target is S2/S3.
  • Otherwise psram_mode = false.
  • Log whether PSRAM DMA mode is enabled.

Kconfig:

  • New bool CAMERA_PSRAM_DMA (default n) under Camera configuration.

Runtime control:

  • New public API:
    • esp_camera_set_psram_mode(bool enable)
    • esp_camera_get_psram_mode(void)
    • esp_camera_reconfigure(const camera_config_t *cfg)

README/test:

  • Remove stale 16MHz XCLK comments.
  • Add short note describing CONFIG_CAMERA_PSRAM_DMA.

Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

@me-no-dev
Copy link
Member

please think of a way to make this runtime configurable. The driver is used in Arduino, which uses a pre-compiled version of the driver and can not change sdkconfig on the fly

@RubenKelevra
Copy link
Contributor Author

Oh okay, wasn't aware of this limitation.

What do you think of putting the capability behind a build flag thought, that would make the binary a bit smaller on devices which don't need it (which do usually have also very limited ROM).

@RubenKelevra RubenKelevra marked this pull request as draft July 18, 2025 08:46
@me-no-dev
Copy link
Member

The driver runs only on ESP32, ESP32S2 and ESP32S3 which do not have such limitation. One option is to have a flag in the camera config (at the end), but preferably is to be set some other way, like a method that would set a flag in the driver, so it does not break existing code.

@RubenKelevra
Copy link
Contributor Author

Okay, will do, as soon as I'm back home.

Since you've implemented it: Have you recently tested this mode?

@RubenKelevra RubenKelevra force-pushed the feat/introduce_flag_to_enable_psram_dma branch 2 times, most recently from ef1c0da to ba2a8be Compare July 18, 2025 22:23
@RubenKelevra RubenKelevra changed the title feat: add CONFIG_CAMERA_PSRAM_DMA for ESP32-S2/S3; remove 16MHz heuristic feat: add PSRAM-DMA flag + runtime API for ESP32-S2/S3; remove 16MHz heuristic Jul 18, 2025
@RubenKelevra RubenKelevra marked this pull request as ready for review July 18, 2025 22:25
@RubenKelevra RubenKelevra marked this pull request as draft July 18, 2025 22:26
…heuristic

Add a Kconfig switch (CONFIG_CAMERA_PSRAM_DMA) to enable camera to PSRAM
DMA copy on ESP32-S2 and ESP32-S3 targets, in favor of removing the
undocumented "set XCLK=16MHz to enable PSRAM DMA" heuristic.

cam_hal.c:
- Select psram_mode = true when CONFIG_CAMERA_PSRAM_DMA && target is S2/S3.
- Otherwise psram_mode = false.
- Log whether PSRAM DMA mode is enabled.

Kconfig:
- New bool CAMERA_PSRAM_DMA (default n) under Camera configuration.

Runtime control:
- New public API:
  - esp_camera_set_psram_mode(bool enable)
  - esp_camera_get_psram_mode(void)
  - esp_camera_reconfigure(const camera_config_t *cfg)

README/test:
- Remove stale 16MHz XCLK comments.
- Add short note describing CONFIG_CAMERA_PSRAM_DMA.
@RubenKelevra RubenKelevra force-pushed the feat/introduce_flag_to_enable_psram_dma branch from ba2a8be to 1484db7 Compare July 18, 2025 23:17
@RubenKelevra RubenKelevra marked this pull request as ready for review July 18, 2025 23:36
@me-no-dev me-no-dev merged commit 2368d94 into espressif:master Jul 21, 2025
30 checks passed
@me-no-dev
Copy link
Member

Have you recently tested this mode?

success depends on different things. It does not work well for JPEG, but works fairly well for other modes. That is if XCLK is 16MHz... other sample clocks do not work well. You can see issues if PSRAM is otherwise heavily used too. Overall experimental feature

@RubenKelevra
Copy link
Contributor Author

Have you recently tested this mode?

success depends on different things. It does not work well for JPEG, but works fairly well for other modes. That is if XCLK is 16MHz... other sample clocks do not work well. You can see issues if PSRAM is otherwise heavily used too. Overall experimental feature

Yeah I think I found the issue why it's not working for JPEGs:

The test for the start of the byte marker for JPEGs does not work as far as I can tell, because the length field is not updated. So previous to #760 it would just try to read random bytes from the memory.

Now it's just returning because there's nothing to read, because the length is zero.

What needs to be done is, that if we get the first EOF for a completed DMA copy that we copy the first section from the PSRAM back into a temporary buffer in the SRAM, and give this temporary buffer to the SOI checker, so it can verify that there's a valid JPEG start.

I'll provide an PR to do this as soon as I get time for that.

@RubenKelevra RubenKelevra deleted the feat/introduce_flag_to_enable_psram_dma branch July 21, 2025 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants